"""
	字典+列表排序总结
        operator模块
"""

# 字典排序: 借助模块operator来排序

from operator import itemgetter

dct = {"a":1,"c":8,"b":3}

# 自定义排序
print(sorted(dct.items(),key=itemgetter(0),reverse=False)) # itemgetter(0) 表示字典的键
print(sorted(dct.items(),key=itemgetter(1),reverse=False)) # itemgetter(1) 表示字典的值


# 进阶: 上面是单纯的一个字典.如果把字典放到列表中
lst = [{"name":"张三","age":18},{"name":"李四","age":16},{"name":"王五","age":20}]
# sorted(iterable,key,reverse)
print(sorted(lst,key=itemgetter("age"),reverse=True))
print(sorted(lst,key=itemgetter("name"),reverse=True))









